﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Provausio.Common.Utility
{
    public class Parser
    {
        /// <summary>
        /// Replaces specified content within a text file with values from a key paired list. Default delimiter is ##MyVariable##
        /// </summary>
        /// <param name="input">Content to be modified</param>
        /// <param name="templateValues">A dictionary of items containing values to be used for replacement. Key: variable to be replaced Value: value to replace it with</param>
        /// <returns></returns>
        public string Parse(string input, Dictionary<string, string> templateValues)
        {
            return Parse(input, "##", templateValues);
        }

        /// <summary>
        /// Replaces specified content within a text file with values from a key paired list
        /// </summary>
        /// <param name="input">Content to be modified</param>
        /// <param name="delimiter">Symbol that marks the variables to be replaced</param>
        /// <param name="templateValues">A dictionary of items containing values to be used for replacement. Key: variable to be replaced Value: value to replace it with</param>
        /// <returns>Modified string</returns>
        public static string Parse(string input, string delimiter, Dictionary<string, string> templateValues)
        {
            
            foreach (var templateValue in templateValues)
            {
                input = input.Replace(string.Format("{0}{1}{0}", delimiter, templateValue.Key), templateValue.Value);
            }
            return input;
        }
    }
}
